package shooter.sound;

import java.applet.Applet;
import java.applet.AudioClip;
import java.net.URL;

/**
 * Represents the sound cache.
 * 
 * @author Michail Tausch
 */
public class SoundCache extends ResourceCache {
	
	/**
	 * Returns a object of the URL.
	 */
	protected Object loadResource(URL url) {
		return Applet.newAudioClip(url);

	}
	
	/**
	 * Returns a AudioClip by name.
	 * @param name
	 * @return
	 */
	public AudioClip getAudioClip(String name) {
		return (AudioClip) getResource(name);
	}
	
	/**
	 * Plays a AudioClip by name.
	 * @param name
	 */
	public void playSound(final String name) {
		new Thread(new Runnable() {
			public void run() {
				getAudioClip(name).play();
			}
		}).start();
	}
	
	/**
	 * Plays a AudioClip in a loop.
	 * @param name
	 */
	public void loopSound(final String name) {
		new Thread(new Runnable() {
			public void run() {
				getAudioClip(name).loop();
			}
		}).start();
	}
	
	/**
	 * Plays a AudioClip by AudioClip.
	 * @param audioClip
	 */
	public void playSound(final AudioClip audioClip) {
		new Thread(new Runnable() {
			public void run() {
				audioClip.play();
			}
		}).start();		
	}

}
